from django.urls import path
from . import views
from django.contrib.auth import views as auth_views
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', views.home, name='home'),
    path('add/', views.add_food, name='add_food'),
    path('scan/', views.scan_query, name='scan_query'),
    path('all/', views.all_foods, name='all_foods'),
    path('register/', views.register, name='register'),
    path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
    path('logout/', auth_views.LogoutView.as_view(), name='logout'),
    path('categories/', views.manage_categories, name='manage_categories'),  # 新增
    path('expired/', views.expired_foods, name='expired_foods'),  # Add this line
    path('expiring/', views.expiring_foods, name='expiring_foods'),  # Add this line
    path('statistics/', views.statistics, name='statistics'),  # 新增
    path('scan/<int:food_id>/', views.scan_record, name='scan_record'),  # 保留一个scan_record路径
    path('locations/', views.manage_locations, name='manage_locations'),
    path('locations/edit/<int:location_id>/', views.edit_location, name='edit_location'),
    path('delete_food/<int:food_id>/', views.delete_food, name='delete_food'),  # 新增删除路由
    path('locations/delete/<int:location_id>/', views.delete_location, name='delete_location'),
    path('categories/edit/<int:category_id>/', views.edit_category, name='edit_category'),
    path('categories/delete/<int:category_id>/', views.delete_category, name='delete_category'),
    path('locations/<int:parent_id>/children/', views.get_child_locations, name='get_child_locations'),
    path('locations/delete/<int:location_id>/', views.delete_location, name='delete_location'),  # 确保这是唯一的删除路径
    path('location_qr/<int:location_id>/', views.location_qr_code, name='location_qr'),
    path('print_qr/', views.print_qr_codes, name='print_qr_codes'),
    path('scan_record/<int:food_id>/', views.scan_record, name='scan_record'),
    path('edit/<int:food_id>/', views.edit_food, name='edit_food'),

]
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)